﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Styx;
using Styx.WoWInternals.WoWObjects;
using Styx.Common;
using System.Windows.Media;
using Styx.WoWInternals;
using System.Threading;
using Styx.CommonBot;
using Styx.CommonBot.Inventory;

namespace ProspectOres
{
    public partial class Form2 : Form
    {

        public Form2()
        {
            InitializeComponent();

            propertyGrid1.SelectedObject = CRSettings.myPrefs;
            propertyGrid2.SelectedObject = CRSettingsMilling.myPrefs;
            propertyGrid3.SelectedObject = CRSettingsDE.myPrefs;

        }
        private void button1_Click(object sender, EventArgs e)
        {
            CRSettings.myPrefs.Save();


            if (CRSettings.myPrefs.AdamantiteOre) { ProsectOre(23425); }
            if (CRSettings.myPrefs.BlackTrilliumOre) { ProsectOre(72094); }
            if (CRSettings.myPrefs.CobaltOre) { ProsectOre(36909); }
            if (CRSettings.myPrefs.CopperOre) { ProsectOre(2770); }
            if (CRSettings.myPrefs.ElementiumOre) { ProsectOre(52185); }
            if (CRSettings.myPrefs.FelironOre) { ProsectOre(23424); }
            if (CRSettings.myPrefs.GhostIronOre) { ProsectOre(72092); }
            if (CRSettings.myPrefs.IronOre) { ProsectOre(2772); }
            if (CRSettings.myPrefs.KypariteOre) { ProsectOre(72093); }
            if (CRSettings.myPrefs.MithrilOre) { ProsectOre(3858); }
            if (CRSettings.myPrefs.ObsidiumOre) { ProsectOre(53038); }
            if (CRSettings.myPrefs.PyritOre) { ProsectOre(52183); }
            if (CRSettings.myPrefs.SaroniteOre) { ProsectOre(36912); }
            if (CRSettings.myPrefs.ThoriumOre) { ProsectOre(10620); }
            if (CRSettings.myPrefs.TinOre) { ProsectOre(2771); }
            if (CRSettings.myPrefs.TitaniumOre) { ProsectOre(36910); }
            if (CRSettings.myPrefs.WhiteTrilliumOre) { ProsectOre(72103); }
            if (CRSettings.myPrefs.SerpentEye) { MakeSerpentEyes(90407); }

            Close();
        }
        public void ProsectOre(uint ore)
        {
            foreach (WoWItem item in StyxWoW.Me.BagItems)
            {
                if (item.Entry == ore && item.StackCount >= 5 && item.BagSlot != -1)
                {
                    if (StyxWoW.Me.FreeNormalBagSlots <= CRSettings.myPrefs.bagSlots)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Not Enough Free Bagspace");
                        break;
                    }
                    while (item.StackCount >= 5 && item.BagSlot != -1)
                    {
                        Logging.Write(Colors.RoyalBlue, "[Prospecting]: Prospecting {0} ", item.Name);
                        SpellManager.Cast(31252);
                        Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                        Thread.Sleep(4500);
                    }
                    if (StyxWoW.Me.FreeNormalBagSlots <= CRSettings.myPrefs.bagSlots)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Not Enough Free Bagspace");
                        break;
                    }
                }
            }
        }
        public void MakeSerpentEyes(uint eye)
        {
            foreach (WoWItem item in StyxWoW.Me.BagItems)
            {
                if (item.Entry == 90407 && item.StackCount >= 10 && item.BagSlot != -1)
                {
                    while (item.StackCount >= 10 && item.BagSlot != -1)
                    {
                        Logging.Write(Colors.RoyalBlue, "[Prospecting]: Making Serpent Eye ");
                        Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                        Thread.Sleep(1500);
                    }
                }
                if (StyxWoW.Me.FreeNormalBagSlots <= CRSettings.myPrefs.bagSlotsSerpent)
                {
                    Logging.Write(Colors.Red, "Stopping Because Not Enough Free Bagspace");
                    break;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            CRSettingsMilling.myPrefs.Save(); ;

            if (CRSettingsMilling.myPrefs.AddersTongue) { MillHerbs(36903); }
            if (CRSettingsMilling.myPrefs.AncientLichen) { MillHerbs(22790); }
            if (CRSettingsMilling.myPrefs.ArthasTear) { MillHerbs(8836); }
            if (CRSettingsMilling.myPrefs.AzsharasVeil) { MillHerbs(52985); }
            if (CRSettingsMilling.myPrefs.Blindweed) { MillHerbs(8839); }
            if (CRSettingsMilling.myPrefs.Briarthorn) { MillHerbs(2450); }
            if (CRSettingsMilling.myPrefs.Bruiseweed) { MillHerbs(2453); }
            if (CRSettingsMilling.myPrefs.Cinderbloom) { MillHerbs(52983); }
            if (CRSettingsMilling.myPrefs.Deadnettle) { MillHerbs(37921); }
            if (CRSettingsMilling.myPrefs.Desecrated) { MillHerbs(89639); }
            if (CRSettingsMilling.myPrefs.Dragonsteeth) { MillHerbs(3819); }
            if (CRSettingsMilling.myPrefs.Dreamfoil) { MillHerbs(13463); }
            if (CRSettingsMilling.myPrefs.DreamingGlory) { MillHerbs(22786); }
            if (CRSettingsMilling.myPrefs.earthroot) { MillHerbs(2449); }
            if (CRSettingsMilling.myPrefs.Fadeleaf) { MillHerbs(3818); }
            if (CRSettingsMilling.myPrefs.Felweed) { MillHerbs(22785); }
            if (CRSettingsMilling.myPrefs.Firebloom) { MillHerbs(4625); }
            if (CRSettingsMilling.myPrefs.FireLeaf) { MillHerbs(39970); }
            if (CRSettingsMilling.myPrefs.FoolsCap) { MillHerbs(79011); }
            if (CRSettingsMilling.myPrefs.GhostMushroom) { MillHerbs(8845); }
            if (CRSettingsMilling.myPrefs.Goldclover) { MillHerbs(36901); }
            if (CRSettingsMilling.myPrefs.GoldenSansam) { MillHerbs(13464); }
            if (CRSettingsMilling.myPrefs.Goldthorn) { MillHerbs(3821); }
            if (CRSettingsMilling.myPrefs.GraveMoss) { MillHerbs(3369); }
            if (CRSettingsMilling.myPrefs.GreenTeaLeaf) { MillHerbs(72234); }
            if (CRSettingsMilling.myPrefs.Gromsblood) { MillHerbs(8846); }
            if (CRSettingsMilling.myPrefs.Heartblossom) { MillHerbs(52986); }
            if (CRSettingsMilling.myPrefs.Icecap) { MillHerbs(13467); }
            if (CRSettingsMilling.myPrefs.Icethorn) { MillHerbs(36906); }
            if (CRSettingsMilling.myPrefs.KhadgarsWhisker) { MillHerbs(3358); }
            if (CRSettingsMilling.myPrefs.Kingsblood) { MillHerbs(3356); }
            if (CRSettingsMilling.myPrefs.Lichbloom) { MillHerbs(36905); }
            if (CRSettingsMilling.myPrefs.Liferoot) { MillHerbs(3357); }
            if (CRSettingsMilling.myPrefs.MageRoyal) { MillHerbs(785); }
            if (CRSettingsMilling.myPrefs.ManaThistle) { MillHerbs(22793); }
            if (CRSettingsMilling.myPrefs.MountainSilversage) { MillHerbs(13465); }
            if (CRSettingsMilling.myPrefs.Netherbloom) { MillHerbs(22791); }
            if (CRSettingsMilling.myPrefs.Nightmarevine) { MillHerbs(22792); }
            if (CRSettingsMilling.myPrefs.peacebloom) { MillHerbs(2447); }
            if (CRSettingsMilling.myPrefs.PurpleLotus) { MillHerbs(8831); }
            if (CRSettingsMilling.myPrefs.Rageveil) { MillHerbs(22787); }
            if (CRSettingsMilling.myPrefs.RainPoppy) { MillHerbs(72237); }
            if (CRSettingsMilling.myPrefs.Silkweed) { MillHerbs(72235); }
            if (CRSettingsMilling.myPrefs.silverleaf) { MillHerbs(765); }
            if (CRSettingsMilling.myPrefs.SnowLily) { MillHerbs(79010); }
            if (CRSettingsMilling.myPrefs.Sorrowmoss) { MillHerbs(13466); }
            if (CRSettingsMilling.myPrefs.Stormvine) { MillHerbs(52984); }
            if (CRSettingsMilling.myPrefs.Stranglekelp) { MillHerbs(3820); }
            if (CRSettingsMilling.myPrefs.Sungrass) { MillHerbs(8838); }
            if (CRSettingsMilling.myPrefs.Swiftthistle) { MillHerbs(2452); }
            if (CRSettingsMilling.myPrefs.TalandrasRose) { MillHerbs(36907); }
            if (CRSettingsMilling.myPrefs.Terocone) { MillHerbs(22789); }
            if (CRSettingsMilling.myPrefs.TigerLily) { MillHerbs(36904); }
            if (CRSettingsMilling.myPrefs.TwilightJasmine) { MillHerbs(52987); }
            if (CRSettingsMilling.myPrefs.Whiptail) { MillHerbs(52988); }
            if (CRSettingsMilling.myPrefs.WildSteelbloom) { MillHerbs(3355); }

            Close();
        }
        public void MillHerbs(uint herb)
        {
            foreach (WoWItem item in StyxWoW.Me.BagItems)
            {
                if (item.Entry == herb && item.StackCount >= 5 && item.BagSlot != -1)
                {
                    while (item.StackCount >= 5 && item.BagSlot != -1)
                    {
                        Logging.Write(Colors.RoyalBlue, "[Milling]:Milling {0} ", item.Name);
                        SpellManager.Cast(51005);
                        Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                        Thread.Sleep(2500);
                    }
                    if (StyxWoW.Me.FreeNormalBagSlots <= 2)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Free Bagspace");
                        break;
                    }
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            CRSettingsDE.myPrefs.Save();


            foreach (WoWItem item in StyxWoW.Me.BagItems)
            {

                if (item.Quality == WoWItemQuality.Uncommon
                    && !item.IsSoulbound
                    && (item.ItemInfo.ItemClass == WoWItemClass.Weapon
                    || item.ItemInfo.ItemClass == WoWItemClass.Armor)
                    && CRSettingsDE.myPrefs.BindonequippedGreen && item.BagSlot != -1)
                {
                    //Logging.Write(Colors.Yellow, "Disenchanting: " + item.Name);
                    SpellManager.Cast(13262);
                    Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                    Thread.Sleep(2500);

                    if (StyxWoW.Me.FreeNormalBagSlots <= 2)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Free Bagspace");
                        break;
                    }
                }
                if (item.Quality == WoWItemQuality.Uncommon
                    && item.IsSoulbound
                    && (item.ItemInfo.ItemClass == WoWItemClass.Weapon
                    || item.ItemInfo.ItemClass == WoWItemClass.Armor)
                    && CRSettingsDE.myPrefs.SoulboundGreen && item.BagSlot != -1)
                {
                    //Logging.Write(Colors.Yellow, "Disenchanting: " + item.Name);
                    SpellManager.Cast(13262);
                    Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                    Thread.Sleep(2500);

                    if (StyxWoW.Me.FreeNormalBagSlots <= 2)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Free Bagspace");
                        break;
                    }
                }
                if (item.Quality == WoWItemQuality.Rare
                    && !item.IsSoulbound
                    && (item.ItemInfo.ItemClass == WoWItemClass.Weapon
                    || item.ItemInfo.ItemClass == WoWItemClass.Armor)
                    && CRSettingsDE.myPrefs.BindonequippedBlue && item.BagSlot != -1)
                {

                    SpellManager.Cast(13262);
                    Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                    Thread.Sleep(2500);

                    if (StyxWoW.Me.FreeNormalBagSlots <= 2)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Free Bagspace");
                        break;
                    }
                }
                if (item.Quality == WoWItemQuality.Rare
                    && item.IsSoulbound
                    && (item.ItemInfo.ItemClass == WoWItemClass.Weapon
                    || item.ItemInfo.ItemClass == WoWItemClass.Armor)
                    && CRSettingsDE.myPrefs.SoulboundBlue && item.BagSlot != -1)
                {

                    SpellManager.Cast(13262);
                    Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                    Thread.Sleep(2500);

                    if (StyxWoW.Me.FreeNormalBagSlots <= 2)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Free Bagspace");
                        break;
                    }
                }
                if (item.Quality == WoWItemQuality.Epic
                    && !item.IsSoulbound
                    && (item.ItemInfo.ItemClass == WoWItemClass.Weapon
                    || item.ItemInfo.ItemClass == WoWItemClass.Armor)
                    && CRSettingsDE.myPrefs.BindonequippedEpic && item.BagSlot != -1)
                {

                    SpellManager.Cast(13262);
                    Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                    Thread.Sleep(2500);

                    if (StyxWoW.Me.FreeNormalBagSlots <= 2)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Free Bagspace");
                        break;
                    }
                }
                if (item.Quality == WoWItemQuality.Epic
                    && item.IsSoulbound
                    && (item.ItemInfo.ItemClass == WoWItemClass.Weapon
                    || item.ItemInfo.ItemClass == WoWItemClass.Armor)
                    && CRSettingsDE.myPrefs.SoulboundEpic && item.BagSlot != -1)
                {

                    SpellManager.Cast(13262);
                    Lua.DoString(string.Format("UseContainerItem({0}, {1})", item.BagIndex + 1, item.BagSlot + 1));
                    Thread.Sleep(2500);

                    if (StyxWoW.Me.FreeNormalBagSlots <= 2)
                    {
                        Logging.Write(Colors.Red, "Stopping Because Free Bagspace");
                        break;
                    }
                }
            }
            Close();
        }
    }
}
